package com.example.qq;

import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.example.qq.Constants.ARouterPath;
import com.example.qq.databinding.ActivityLoginBinding;

@Route(path = ARouterPath.LOGIN_ACT)
public class LoginActivity extends AppCompatActivity {

    ActivityLoginBinding mBingding;
    LoginVM loginVM;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBingding = DataBindingUtil.setContentView(this, R.layout.activity_login);

        loginVM = new ViewModelProvider(this,
                ViewModelProvider.AndroidViewModelFactory.getInstance(getApplication()))
                .get(LoginVM.class);
        mBingding.setVm(loginVM);

        setMode();

        setOnClickListener();
    }

    private void setOnClickListener() {
        mBingding.setOnClick(v -> {
            Toast.makeText(LoginActivity.this, "暂未开放", Toast.LENGTH_SHORT).show();
        });

        mBingding.go.setOnClickListener(v -> {
            if (TextUtils.isEmpty(loginVM.getUserName().getValue())) {
                Toast.makeText(this, "请输入用户名", Toast.LENGTH_SHORT).show();
                return;
            }
            if (TextUtils.isEmpty(loginVM.getPassword().getValue())) {
                Toast.makeText(this, "请输入密码", Toast.LENGTH_SHORT).show();
                return;
            }
            ARouter.getInstance().build(ARouterPath.MAIN_ACT).navigation();
        });
    }

    /**
     * 设置沉浸式主题界面
     */
    private void setMode() {
        //获取到当前界面的decorView
        View decorView = getWindow().getDecorView();
        int option = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION  //这个属性是让应用占用系统导航栏的空间
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;

        getWindow().setNavigationBarColor(Color.WHITE);
        getWindow().setStatusBarColor(Color.WHITE);
        //设置UI可见性参数
        decorView.setSystemUiVisibility(option);
        //将actionBar也隐藏
        ActionBar actionBar = getSupportActionBar();
        actionBar.hide();
    }

}